package com.jetpackmvp.utils

import android.app.AlertDialog
import android.content.Context
import android.view.View
import com.jetpackmvp.R


/**
 * @author: GY.LEE
 * @date: 2019-06-06
 * @Des:
 */
class ProgressDialog(val mContext: Context) : AlertDialog.Builder(mContext, R.style.ProcessDialog) {

    private var title = "正在加载数据"
    private var alertDialog: AlertDialog? = null

    /**
     * 不可以取消的 Dialog
     */
    fun showWithCancel() {
        showDialog(true)
    }

    /**
     * 可以取消的 Dialog
     */
    fun showNormal() {
        showDialog(false)
    }

    private fun showDialog(canCancel: Boolean) {
        alertDialog = super.show()
        val view = View.inflate(mContext, R.layout.layout_progress_dialog, null)
        alertDialog?.window?.setContentView(view)
        alertDialog?.setCancelable(canCancel)
    }

    fun dismiss() {
        if (alertDialog != null && alertDialog!!.isShowing()) {
            alertDialog?.dismiss()
        }
    }

    fun setTitle(text: String): ProgressDialog {
        title = text
        return this
    }
}